local temp = {}
local stock = 0
for i=1, #KEYS do
	stock = redis.call("HINCRBY", KEYS[i], "stock", -ARGV[i])
	redis.call("HINCRBY", KEYS[i], "sales", ARGV[i])
	temp[i] = KEYS[i]
	if stock < 0 then
		break
	end
end

if stock < 0 then
	for i=1, #temp do
		redis.call("HINCRBY", temp[i], "stock", ARGV[i])
		redis.call("HINCRBY", temp[i], "sales", -ARGV[i])
	end
	return 0
else
	return 1
end
